package com.splant.android.smart.SystemDefinedLevel.Notifications;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;


/**
 * Created by JimOPC on 15-1-29.
 */
public class Notice {

    private Context context;
    public Notice(Context context)
    {
        this.context=context;
    }
    public void ShowNotice(int icon,String noticeTitle,String noticeContent,Class<?> actionActivity)
    {
         //定义NotificationManager
        NotificationManager barmanager=(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
        //构建一个通知对象(需要传递的参数有三个,分别是图标,标题和 时间)

        Notification.Builder builder = new Notification.Builder(context);
        builder.setContentTitle("通知");
        builder.setContentText("message");

        Intent intent = new Intent(context,actionActivity);
        intent.addCategory(Intent.CATEGORY_LAUNCHER);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
        PendingIntent pendingIntent = PendingIntent.getActivity(context,0,intent,0);

        builder.setContentIntent(pendingIntent);//执行intent

        Notification notification = builder.getNotification();

        notification.flags =  Notification.FLAG_AUTO_CANCEL;
        notification.defaults = Notification.DEFAULT_SOUND;//声音默认

        barmanager.notify(100, notification);//发动通知,id由自己指定，每一个Notification对应的唯一标志

    }
}
